package com.ljp.server.http;

import com.ljp.server.Server;
import io.vertx.core.Vertx;

/**
 * ClassName: VertxHttpServer
 * Package: com.ljp.server
 * Description:
 *
 * @Author: ljp
 * @Create: 2025/6/4-下午 02:53
 * @Version: 1.0
 */
public class VertxHttpServer implements Server {
    /**
     * 启动服务
     *
     * @param port 监听端口号
     */
    @Override
    public void doStart(int port) {
        // 创建 Vert.x 实例
        Vertx vertx = Vertx.vertx();
        // 创建 HTTP 服务器
        io.vertx.core.http.HttpServer httpServer = vertx.createHttpServer();

        // 处理请求
        httpServer.requestHandler(new HttpServerHandler());

        // 启动服务器
        httpServer.listen(port, result -> {
            if (result.succeeded()) {
                System.out.println("HTTP server started on port " + port);
            } else {
                System.err.println("Failed to start HTTP server: " + result.cause());
            }
        });
    }
}
